import {Component, OnInit} from '@angular/core';
import {CommonService} from '../common.service';

@Component({
    selector: 'app-index',
    templateUrl: './index.component.html',
    styleUrls: ['./index.component.css']
})
export class IndexComponent implements OnInit {
    swiper: any;
    actors = [];
    girls = [];
    tags = [];

    constructor(public Service: CommonService) {
    }

    ngOnInit() {
        this.swiper = new Swiper('.hy-slide', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            autoplay: 3000,
            nextButton: '.swiper-button-next',
            prevButton: '.swiper-button-prev',
        });

        this.getActors();
        this.getGirls();
        this.getTags();
    }

    /**
     * 获取女神图片列表
     */
    getGirls() {
        const $this = this;
        const params = {
            channel: 'girls',
            row: 12,
        };
        this.Service.post('index/getlist', params).subscribe(res => {
            this.Service.resultHandler(res, function (msg, data) {
                $this.girls = data.data;
            });
        });
    }

    /**
     * 获取热门标签
     */
    getTags() {
        const $this = this;
        const params = {
            order: 'click',
            channel: 'video',
            row: 24,
        };
        this.Service.post('index/gettags', params).subscribe(res => {
            this.Service.resultHandler(res, function (msg, data) {
                $this.tags = data;
            });
        });
    }

    getActors() {
        const $this = this;
        const params = {
            order: 'click',
            row: 12,
        };

        this.Service.post('index/getactors', params).subscribe(res => {
            this.Service.resultHandler(res, function (msg, data) {
                $this.actors = data;
            });
        });
    }
}
